﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Helper_Ji
{
    public class Helper_Sip
    {
        public sealed class SipHeadFieldName
        {
            /// <summary>
            /// A 
            /// </summary>
            public const string Authorization = "A";
            /// <summary>
            /// I
            /// </summary>
            public const string CallID = "I";
            /// <summary>
            /// M
            /// </summary>
            public const string Contact = "M";
            /// <summary>
            /// E
            /// </summary>
            public const string ContentEncoding = "E";
            /// <summary>
            /// L
            /// </summary>
            public const string ContentLength = "L";
            /// <summary>
            /// c
            /// </summary>
            public const string ContentType = "C";
            /// <summary>
            /// Q
            /// </summary>
            public const string CSeq = "Q";
            /// <summary>
            /// D
            /// </summary>
            public const string Date = "D";
            /// <summary>
            /// EP
            /// </summary>
            public const string EndPoints = "EP";
            /// <summary>
            /// N
            /// </summary>
            public const string Event = "N";
            /// <summary>
            /// X
            /// </summary>
            public const string Expires = "X";
            /// <summary>
            /// F
            /// </summary>
            public const string From = "F";
            /// <summary>
            /// XI
            /// </summary>
            public const string MessageID = "XI";
            /// <summary>
            /// RB
            /// </summary>
            public const string ReferredBy = "RB";
            /// <summary>
            /// RT
            /// </summary>
            public const string ReferTo = "RT";
            /// <summary>
            /// RQ
            /// </summary>
            public const string Require = "RQ";
            /// <summary>
            /// RM
            /// </summary>
            public const string RosterManager = "RM";
            /// <summary>
            /// SO
            /// </summary>
            public const string Source = "SO";
            /// <summary>
            /// K
            /// </summary>
            public const string Supported = "K";
            /// <summary>
            /// T
            /// </summary>
            public const string To = "T";
            /// <summary>
            /// UK
            /// </summary>
            public const string Unsupported = "UK";
            /// <summary>
            /// W
            /// </summary>
            public const string WWWAuthenticate = "W";

            /// <summary>
            /// AL 
            /// 不知道这个AL是什么意思
            /// </summary>
            public const string AL = "AL";
        }

        public class SipMethodName
        {
            /// <summary>
            /// A
            /// </summary>
            public const string Ack = "A";
            /// <summary>
            /// BN
            /// </summary>
            public const string Benotify = "BN";
            /// <summary>
            /// B
            /// </summary>
            public const string Bye = "B";
            /// <summary>
            /// c
            /// </summary>
            public const string Cancel = "C";
            /// <summary>
            /// IN
            /// </summary>
            public const string Info = "IN";
            /// <summary>
            /// I
            /// </summary>
            public const string Invite = "I";
            /// <summary>
            /// M
            /// </summary>
            public const string Message = "M";
            /// <summary>
            /// NEG
            /// </summary>
            public const string Negotiate = "NEG";
            /// <summary>
            /// N
            /// </summary>
            public const string Notify = "N";
            /// <summary>
            /// O
            /// </summary>
            public const string Options = "O";
            /// <summary>
            /// REF
            /// </summary>
            public const string Refer = "REF";
            /// <summary>
            /// R
            /// </summary>
            public const string Register = "R";
            /// <summary>
            /// S
            /// </summary>
            public const string Service = "S";
            /// <summary>
            /// SUB
            /// </summary>
            public const string Subscribe = "SUB";

            public const string Empty = "";
        }

        public static class SipHelper
        {
            public static string GetCSeqMethod(SipHeadField field)
            {
                //Q: 2 R
                string raw = field.ToString();
                if (!raw.StartsWith(SipHeadFieldName.CSeq))
                {
                    throw new ArgumentException("can't get CSeqMethod from :" + field.Value);
                }
                string[] arr = raw.Split(new char[] { ' ' });
                if (arr.Length > 1)
                {
                    return arr[2];
                }
                return string.Empty;
            }
        }
    }
}
